


<!--ztree部分-->
<input type="hidden" id="operation" name="operation">



<div ng-controller="ztreeEditCtrl">
  <!--右键菜单-->
  <div id="rMenu" class="list-group" >  
    <a href="javascript:void(0);" class="list-group-item" ng-click="addTreeNode();">添加节点</a>  
    <a href="javascript:void(0);" class="list-group-item" ng-click="editTreeNode();">编辑节点</a>  
    <a href="javascript:void(0);" class="list-group-item" ng-click="deleteTreeNode();">删除节点</a>  

  </div> 




  <!--隐藏ztree编辑页-->
  <div id="ztreeEditDiv" style="display: none;" >
    <div class="wrapper-md"  >
      <div class="panel panel-default">
        <div>
          <div class="row">
            <div class="col-sm-12" >
              <form name="form-contact" class="form-horizontal"  ng-submit="processForm()">
                <div class="panel-body">
                 


                  <div class="form-group">
                    <label class="col-sm-3 control-label">上级菜单</label>
                    <div class="col-sm-9">


                      <div class="col-sm-9" style="margin-top: 6px;">
                        <span>{{father.ClassName}}</span>
                      </div>

                    </div>
                  </div>
                  <div class="line line-dashed b-b line-lg pull-in"></div>

                  <div class="form-group">
                    <label class="col-sm-3 control-label">分类名称</label>
                    <div class="col-sm-9">
                     <input type="text" class="form-control" placeholder="分类名称" ng-model="contact.ClassName" required >
                   </div>
                 </div>
                 <div class="line line-dashed b-b line-lg pull-in"></div>


                 <div class="form-group">
                  <label class="col-sm-3 control-label">图标</label>
                  <div class="col-sm-9">
                   <input type="text" class="form-control" placeholder="图标" ng-model="contact.ClassSmallIcon"  >
                 </div>
               </div>

               <div class="line line-dashed b-b line-lg pull-in"></div>

               <div class="form-group">
                <label class="col-sm-3 control-label">备注</label>
                <div class="col-sm-9">
                 <input type="text" class="form-control" placeholder="备注" ng-model="contact.ClassRemark"  >
               </div>
             </div>
             <div class="line line-dashed b-b line-lg pull-in"></div>

             <div class="form-group">
              <label class="col-sm-3 control-label">排序</label>
              <div class="col-sm-9">
               <input type="Number" class="form-control" placeholder="排序" ng-model="contact.ClassDisplayOrder" required >
             </div>
           </div>



           <!--隐藏字段-->
           <input type="hidden"  ng-model="contact.Id"  >
           <input type="hidden"  ng-model="contact.FatherId"  >
           <input type="hidden"  ng-model="contact.ClassUuid"  >
           <input type="hidden"  ng-model="contact.AdderId"  >
           <input type="hidden"  ng-model="contact.AdderName"  >
           <input type="hidden"  ng-model="contact.AddTime"  >
           <input type="hidden"  ng-model="contact.UpdaterId"  >
           <input type="hidden"  ng-model="contact.UpdaterName"  >
           <input type="hidden"  ng-model="contact.UpdateTime"  >
           <input type="hidden"  ng-model="contact.DelFlag" ng-init="contact.DelFlag='0'" >

           <!--隐藏字段-->




           <footer class="panel-footer text-right bg-light lter">
            <button type="submit" class="btn btn-success">提交</button>
          </footer>

        </div>
      </form>
    </div>
  </div>
</div>
</div>
</div>
<!--隐藏ztree编辑页-->


</div>
</div>

<!--ztree部分-->
<script type="text/javascript">




 var ztreeUrl  =  API_URL +"channel_class?query=delflag:0";
 $(document).ready(function(){
      //初始化ztree
      onloadZTree(ztreeUrl,'频道分类');//调用ztree-mine.js里的方法
    });

//angularjs总控制器
app.controller('ztreeEditCtrl', function($scope, $http,$state) {

//添加节点
$scope.addTreeNode=function(){
 $scope.contact.ClassName = '';
 var id = $("#operation").val();
 console.log('id:'+id);
 if(id>0){
   var fatherUrl  =  API_URL +"channel_class?query=delflag:0,Id:"+id;
   var father = MY_ASYNC_AJAX(fatherUrl)[0];
   $scope.father =   father;
   $scope.contact.FatherId = father.Id;
 }else{
   $scope.contact.FatherId = 0 ;
   $scope.father= {Id:0,ClassName:'顶级菜单'};
 }

 delete $scope.contact['Id'];  
 
 top.layer.open({
  type: 1,
  title: '输入分类信息',
  fix: false,
        maxmin: true, //开启最大化最小化按钮
        shadeClose: true,
        shift: 4,
        shade: [0.5],
        //skin: 'layui-layer-rim',边框
        move: false,
        area: ['600px', '510px'],
        content: $('#ztreeEditDiv'),
        yes: function (index, layero) {
          $scope.contact = null;
          $scope.father = null;
        },
        no: function(){
         $scope.contact = null;
         $scope.father = null;
       }
     });
}

//删除节点
$scope.deleteTreeNode=function(){
  var id = $("#operation").val();
  top.layer.confirm('您确定删除吗', function(index){
    var detailUrl  =  API_URL +"channel_class?query=delflag:0,Id:"+ id;
    var detail = MY_ASYNC_AJAX(detailUrl);
    var formData = detail[0];
    formData.delflag = '1';
    var delUrl =   API_URL+"channel_class";
    $.ajax({  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : delUrl+'/'+id, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                    console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 
                    top.layer.msg('删除成功', {icon: 6});
                    //2.成功跳转页面
                  onloadZTree(ztreeUrl,'频道分类');//调用ztree-mine.js里的方法
                  $("#operation").value = '';
                  
                }  
              }); 
    top.layer.close(index);
  });
  
}





//编辑节点
$scope.editTreeNode=function(){
 var id = $("#operation").val();
 var znUrl  =  API_URL +"channel_class?query=delflag:0,id:"+id;
 var detailTree  = MY_ASYNC_AJAX(znUrl);
 detailTree[0].ClassDisplayOrder = Number(detailTree[0].ClassDisplayOrder);
 $scope.contact =   detailTree[0];
 if(detailTree[0].FatherId>0){
   var fatherUrl  =  API_URL +"channel_class?query=delflag:0,Id:"+ detailTree[0].FatherId;

   var father = MY_ASYNC_AJAX(fatherUrl)[0];

   $scope.father =   father;
   $scope.contact.FatherId = father.Id;
 }else{
   $scope.contact.FatherId = 0 ;
   $scope.father= {Id:0,ClassName:'顶级菜单'};
 }



 
 top.layer.open({
   type: 1,
   title: '输入栏目信息',
   fix: false,
       maxmin: true, //开启最大化最小化按钮
       shadeClose: true,
       shift: 3,
       shade: [0.5],
       //skin: 'layui-layer-rim',边框
       maxmin: true,
       move: false,
       area: ['600px', '510px'],
       content: $('#ztreeEditDiv'),
       shadeClose: false,
       yes: function (index, layero) {
        $("#operation").value = '';
      },
      no: function(){
       $scope.contact = '';
       $("#operation").value = '';
     }
   });



}


$scope.removeTreeNode = function(){
  
}






  //表单提交开始
  $scope.processForm= function (){
  //1.参数处理
//发起POST请求
var postInfoUrl = API_URL+"channel_class";
var formData =  $scope.contact;

  //1.参数处理
  formData.AddTime = getNowDBFormatDate();
  formData.UpdateTime = getNowDBFormatDate();
  formData.ClassLevel =  '1';
  formData.AdderId = 1;
  formData.AdderName = '1';
  formData.UpdaterId = 1;
  formData.UpdaterName = '1';
  formData.ClassUuid='';
  formData.ClassDisplayOrder =  formData.ClassDisplayOrder+'';

  console.log(JSON.stringify(formData));


  if("undefined" != typeof(formData.Id)){

    $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl+'/'+formData.Id, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                    console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 
                    onloadZTree(ztreeUrl,'频道分类');//调用ztree-mine.js里的方法
                    $("#operation").value = '';
                  }  
                }); 

  }else{

    $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'post', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                    console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 
                   onloadZTree(ztreeUrl,'频道分类');//调用ztree-mine.js里的方法
                   $("#operation").value = '';
                 }  
               }); 

  }



  top.layer.msg('保存成功', {icon: 6});

  layer.closeAll();

  onloadZTree(ztreeUrl,'频道分类');
  
}

 //表单提交结束







});




//左边ztree,onclick事件
function zTreeOnClickDetail(event, treeId, treeNode){

  var operation = $("#operation").val();
  var classId = treeNode.id;
  if(classId==0){
  }
  var ztreeUrl  =   API_URL +"channel_class?query=delflag:0,id:"+classId+"&sortby=ClassDisplayOrder&order=asc&limit=9999&offset=0";
  var list = MY_ASYNC_AJAX(ztreeUrl);
  //搜索datatables
  var table = $('#myTable').DataTable();

  var newUrl =  API_URL+"channel_class/"+classId+"/channel_info";
  console.log(newUrl);

  if(0==classId){
    newUrl =  API_URL + "channel_info?query=delflag:0";
  }
  table.ajax.url(newUrl).load();

}



</script>

